<?php
class Counter {
private $counter = 0;
public function increment() {
$this->counter++;
return $this;
}
public function getCount() {
return $this->counter;
}
}
$counter = new Counter();
$anotherCounter = $counter->increment();
echo "counter: " . $counter->getCount() . "\n";
echo "anotherCounter: " . $anotherCounter->getCount() . "\n\n";
$anotherCounter->increment();
echo "counter: " . $counter->getCount() . "\n";
echo "anotherCounter: " . $anotherCounter->getCount() . "\n";
1